package net.dgg.rz.common.service;

import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.rz.common.dao.AllotRecordDao;
import net.dgg.rz.common.dao.OrderDao;
import net.dgg.rz.common.entity.Order;
import net.dgg.rz.common.entity.dto.AllotRecordDto;
import net.dgg.rz.common.utils.DataPermissionUtils;
import net.dgg.rz.common.utils.SearchUtils;
import net.dgg.rz.common.utils.ValidateUtils;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 销售订单order
 *<p>@Package: net.dgg.rz.common.service</p>
 *<p>@Title：OrderService</p>
 *<p>@description:</p>
 *<p>@author liulei</p>
 *<p>@date 2018年8月31日</p>
 *<p>@Company dgg</p>
 */
@Service
public class AllotRecordService {

	
	@Autowired
	private AllotRecordDao allotRecordDao;
	@Autowired
	private SearchUtils searchUtils;
	@Autowired
	private DesUtil desUtil;
	@Autowired
	private TranslateUtil translateUtil;
	@Autowired
	private DataPermissionUtils dataPermissionUtils;
	@Autowired
	private SessionManager sessionManager;

	/**
	 * 分页查询生产订单列表数据
	 */
	@Transactional
	public List<AllotRecordDto> allotRecordWithPage(Map params){
		UserEntity userEntity=searchUtils.getcurrUser(params);
		ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "当前未登录，请登录后重试");
		params.put("orderDir", "desc");
		params.put("orderColumn", "t.update_time");
		searchUtils.paramsOperate(params);
		dataPermissionUtils.allotRecordDataAccess(params);
		List<AllotRecordDto> allotRecordDtoList=allotRecordDao.allotRecordWithPage(params);
		String[] transColum = {"originCode", "status","suspendReason"};
		allotRecordDtoList = translateUtil.translateList(transColum, allotRecordDtoList);
		//隐藏字段
		String[] hideColum = {"customerPhone"};
		allotRecordDtoList = desUtil.decryptList(hideColum, allotRecordDtoList);
		allotRecordDtoList = CustomerNumberEncryptionUtil.encryptionList(hideColum, allotRecordDtoList);
		return allotRecordDtoList;
	}
}
